package com.zhuimeng.controller;

import com.zhuimeng.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class LoginController {

    @Autowired
    LoginService service;

    @RequestMapping("login")
    @ResponseBody
    public Boolean Login(String name, String pwd, HttpServletRequest request){
        boolean logined = service.login(name, pwd);
        if (logined){
            request.getSession().setAttribute("logined",true);
        }else {
            request.getSession().setAttribute("logined",false);
        }
        return logined;
    }
    @RequestMapping("/index")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("index");
        return modelAndView;
    }

    @RequestMapping("toLogin")
    public ModelAndView toLogin(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("login");
        return modelAndView;
    }
}
